package com.linjiu.easyphotos.client;

import com.linjiu.easyphotos.models.album.entity.Photo;

import java.util.ArrayList;

/**
 * 项目名称：com.linjiu.easyphotos.client
 * 创建人:LuoFG
 * 创建时间:2024/5/31  15:43
 * 描述:
 * 作用:
 */
public class PreviewClient {

    private static class InstanceHolder {
        private static PreviewClient instance = new PreviewClient();
    }

    private static PreviewClient getInstance() {
        return PreviewClient.InstanceHolder.instance;
    }

    public static PreviewClient getClient() {
        return getInstance();
    }


    //是否显示更多 仅图片预览使用
    private boolean isShowMore = false;

    private MoreClickListener moreClickListener;
    private GetSaveShowImageListener getSaveShowImageListener;
    private RefreshShowImageListener refreshShowImageListener;

    public void reset(){
        isShowMore=false;
        moreClickListener=null;
    }


    public interface MoreClickListener{
        void click(PhotoMoreResultBean photoMoreResultBean);
    }

    /***保存图片  本地需要注册的监听-Start***/
    public interface GetSaveShowImageListener {
        void save(int position);
    }

    /***保存图片  本地需要注册的监听-Start***/
    public interface RefreshShowImageListener {
        void refresh(ArrayList<Photo> photos,int position);
    }


    /**
     * 刷新数据源
     */
    public void runRefreshShowImage(ArrayList<Photo> photos,int position) {
         if (refreshShowImageListener != null) {
            refreshShowImageListener.refresh(photos,position);
        }}

    /**
     * 添加刷新数据源监听
     */
    public PreviewClient addRefreshShowImageListener(RefreshShowImageListener refreshShowImageListener) {
        this.refreshShowImageListener = refreshShowImageListener;
        return this;
    }

    //运行其他注册保存图片的方法地方
    public void runGetSaveShowImage(int position) {
        if (getSaveShowImageListener != null) {
            getSaveShowImageListener.save(position);
        }
    }
    //拿到图片后传递给注册保存图片方法的地方
    public PreviewClient addGetSaveShowImageListener(GetSaveShowImageListener getSaveShowImageListener) {
        this.getSaveShowImageListener = getSaveShowImageListener;
        return this;
    }

    public boolean isShowMore() {
        return isShowMore;
    }

    public PreviewClient setShowMore(boolean showMore) {
        isShowMore = showMore;
        return this;
    }

    public PreviewClient addMoreClickListener(MoreClickListener moreClickListener) {
        this.moreClickListener = moreClickListener;
        return this;
    }

    public void runMoreClickLister(PhotoMoreResultBean photoMoreResultBean){
        if(moreClickListener!=null){
            moreClickListener.click(photoMoreResultBean);
        }
    }



}
